home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 5.5 KB | 223 lines | [TEXT/ttxt] |
- --<<<
- class RadioButton(GenericButton)
- class variables
- uncheckedStencil : (importDIB "media/radio.bmp")
- checkedStencil : (importDIB "media/radioc.bmp")
- clickedStencil :(importDIB "media/radiodp.bmp")
- instance variables
- frame
- stencilTransform
- fill
- _font
- _text
- end
-
- class CheckBox(RadioButton)
- class variables
- uncheckedStencil : (importDIB "media/check.bmp")
- checkedStencil : (importDIB "media/checkc.bmp")
- clickedStencil :(importDIB "/media/checkdp.bmp")
- end
-
- method init self {class RadioButton} #rest args #key
- fill:(whiteBrush) \
- font:(theSystemFont) \
- text:("Hello") \
- boundary: \
- frame:(undefined)->
- (
- self._text := new TextStencil font:font.font \
- size:font.fontSize string:text
- local bbox
- if (boundary = unsupplied) then (
- bbox := copy self._text.bbox
- bbox.width := bbox.width + (getClass self).checkedStencil.bbox.width + 10
- InsetRect bbox -3 -3 @mutate
- MoveToZero bbox
- )
- else
- bbox := boundary
- apply nextMethod self boundary:bbox args
- self.frame := frame
- self.stationary := fill <> undefined
- self.fill := fill
- self.stencilTransform := mutableCopy identityMatrix
- self._font := font
- self
- )
-
- method recalcRegion self {class RadioButton} ->
- (
- nextMethod self
- local xOffset := 3
- if (self.frame != undefined) do (
- SetBoundary self.frame self.boundary
- xOffset := xOffset + 2
- )
- SetTo self.stencilTransform self.globalTransform
- local yOffset := (self.boundary.height - (getClass self).clickedStencil.bbox.height)/2
- translate self.stencilTransform xOffset yOffset
- )
-
- method activate self {class RadioButton} ->
- (
- if (self.enabled) do
- if (self.toggledOn) then
- toggleOff self
- else
- toggleOn self
- nextMethod self
- )
-
- method draw self {class RadioButton} surf clip -> (
- if (self.fill <> undefined) do
- fill surf self.globalBoundary clip identityMatrix self.fill
- local drawStencil
- if (self.pressed) then
- drawStencil := (getClass self).clickedStencil
- else if (self.toggledOn) then
- drawStencil := (getClass self).checkedStencil
- else
- drawStencil := (getClass self).uncheckedStencil
- fill surf drawStencil clip self.stencilTransform BlackBrush
- local xOffset := 5 + drawStencil.bbox.width
- local yOffset := drawStencil.bbox.height
- ThreadCriticalUp()
- translate self.stencilTransform xOffset yOffset
- fill surf self._text clip self.stencilTransform BlackBrush
- translate self.stencilTransform (-xOffset) (-yOffset)
- ThreadCriticalDown()
- if (self.frame <> undefined) do
- drawLoweredFrame self.frame surf clip self.globalTransform
- NextMethod self surf clip
- )
-
- method textGetter self {class RadioButton} ->
- (
- self._text.string
- )
-
- method textSetter self {class RadioButton} newString->
- (
- self._text.string := newString
- notifyChanged self false
- newString
- )
-
- method fontGetter self {class RadioButton} ->
- (
- self._font
- )
-
- method fontSetter self {class RadioButton} newFont->
- (
- self._text.font := newFont.font
- self._text.size := newFont.fontSize
- self._font := newFont
- )
-
- class RadioGroup (TwoDSpace)
- instance vars
- controller
- itemList ---- The array of TextRadioButtons
- value ---- The value of the currently choosen radio button
- frame
- end
-
- method init self {class RadioGroup} #rest args #key
- boundary: \
- font:(theSystemFont) \
- itemList: \
- itemClass:(RadioButton) \
- itemBoundary: \
- fill:(WhiteBrush) \
- orientation:(@vertical) ->
- (
- local dynamicSetter,staticSetter,singleGetter,multipleGetter
- local singleSetter,multipleSetter
- local itemSpan
- if (orientation == @horizontal) then (
- staticSetter := ySetter
- dynamicSetter := xSetter
- singleGetter := heightGetter
- multipleGetter := widthGetter
- singleSetter := heightSetter
- multipleSetter := widthSetter
- )
- else (
- staticSetter := xSetter
- dynamicSetter := ySetter
- singleGetter := widthGetter
- multipleGetter := heightGetter
- singleSetter := widthSetter
- multipleSetter := heightSetter
- )
- apply NextMethod self boundary:boundary fill:fill args
- local listSize := size itemList
- local i
- if (boundary <> unsupplied) then (
- itemSpan := ((multipleGetter boundary) - 4)/ listSize
- )
- else (
- if (itemBoundary == unsupplied) then
- if (orientation == @vertical) then
- itemSpan := font.leading + 6
- else
- itemSpan := 50 -- arbitrary number
- else
- itemSpan := multipleGetter itemBoundary
- )
- local dynamicOffset := 2
- local singleSpan := 0
- print itemSpan
- for i := 1 to listSize do (
- local rb := new itemClass boundary:itemBoundary fill:(undefined) \
- font:font text:(getNth itemList i)
- dynamicSetter rb dynamicOffset --rb.y := yOffset
- staticSetter rb 2
- append self rb
- if ((singleGetter rb.boundary) > singleSpan) do
- singleSpan := (singleGetter rb.boundary)
- dynamicOffset := dynamicOffset + itemSpan
- )
- if (boundary = unsupplied) do (
- singleSetter self.boundary (singleSpan + 4)
- multipleSetter self.boundary (itemSpan*listSize + 4)
- )
- self.stationary := true
- self.controller := new RadioButtonController
- self.controller.space := self
- self.controller.wholeSpace := true
- self.itemList := itemList
- self.frame := new Frame
- self
- )
-
- method draw self {class RadioGroup} surf clip ->
- (
- NextMethod self surf clip
- drawLoweredFrame self.frame surf clip self.globalTransform
- )
-
- method valueGetter self {class RadioGroup} ->
- (
- local nth := getKeyOne self self.controller.chosenToggle
- getNthKey self.itemList nth
- )
-
- method valueSetter self {class RadioGroup} newVal ->
- (
- local ord := (getone self.itemList newVal)
- local i := getOrdOne self.itemList ord
- if (i <> 0) do
- self.controller.chosenToggle := self[i]
- )
-
- method recalcRegion self {class RadioGroup} ->
- (
- nextMethod self
- setBoundary self.frame self.boundary
- )
-
- -->>>
-